var FM_AutoCAD_API = Class.create();
FM_AutoCAD_API.prototype = {
    initialize: function () {
    },

    type: 'FM_AutoCAD_API',

    getData: function (fmClass, sys_id) {
        var json = [];
        var gr = new GlideRecord("x_lsmcb_fm_" + fmClass);
        if (sys_id) {

            if (fmClass === "room") {
                gr.addQuery("floor", sys_id);
            }
            if (fmClass === "floor") {
                gr.addQuery("building", sys_id);
            }
        }

        gr.query();
        while (gr.next()) {
            json.push({
                id: gr.getValue("id"),
                name: gr.getValue("name"),
                sys_id: gr.getValue("sys_id")
            });
        }
        return json;
    },

    getBuildings: function (){
        return this.getData('building');
    },

    getFloors: function(sys_id) {
        return this.getData('floor', sys_id);
    },

    getRooms: function(sys_id) {
        return this.getData('room', sys_id);
    }
};